import { useAuthStore } from '@/store'

/** 权限判断 */
export function usePermission() {
  const authStore = useAuthStore()
  function hasPermission(
    permission: any,
  ) {
    if (!permission)
      return true

    if (!authStore.userInfo)
      return false

    const p = authStore.permissions

    // let has = permissions ===  ["*:*:*"]
    let has = p.includes("*:*:*");
    if (!has) {
      if (p.includes(permission))
        has = true
    }
    return has
  }

  return {
    hasPermission,
  }
}
